package cn.pegasus.teamwork.pegasus.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.iyizhan.teamwork.base.service.impl.BaseServiceImpl;
import cn.pegasus.teamwork.pegasus.entity.BussUserIntegraldetail;
import cn.pegasus.teamwork.pegasus.entity.BussUserIntegraltotal;
import cn.pegasus.teamwork.pegasus.mapper.BussUserIntegraldetailMapper;
import cn.pegasus.teamwork.pegasus.mapper.BussUserIntegraltotalMapper;
import cn.pegasus.teamwork.pegasus.service.BussUserIntegraltotalService;

/**
 * @author ryan.bian
 * @version 
 */
@Service("bussUserIntegraltotalService")
public class BussUserIntegraltotalServiceImpl extends BaseServiceImpl<BussUserIntegraltotal, BussUserIntegraltotalMapper> implements BussUserIntegraltotalService {
	// 注入当前dao对象
    @Autowired
    private BussUserIntegraltotalMapper bussUserIntegraltotalMapper;
    
    @Autowired
    private BussUserIntegraldetailMapper bussUserIntegraldetailMapper;

    public BussUserIntegraltotalServiceImpl() {
        setMapperClass(BussUserIntegraltotalMapper.class, BussUserIntegraltotal.class);
    }

	/**
	 * 对用户充值时，积分的处理
	 */
	public void handleUserIntegraltotal(int ordId,int userId, int integralNums) {
		BussUserIntegraltotal bi = new BussUserIntegraltotal();
		bi.setUserId(userId);
		bi = bussUserIntegraltotalMapper.selectSingle(bi);
		if(bi != null ){
			// 积分总账户
			int integ =bi.getIntegralTotal() + integralNums;
			bi.setIntegralTotal(integ);
			bi.setIntegralDescription("充值赠送积分");
			bussUserIntegraltotalMapper.updateByEntity(bi);
	
			// 积分明细
			BussUserIntegraldetail bid = new BussUserIntegraldetail();
			bid.setUserId(userId);
			bid.setIntegralSource(ordId);
			bid.setIntegralType(1);
			bid.setIntegralNums(integralNums);
			bussUserIntegraldetailMapper.insertByEntity(bid);
		}
		
	}
    
 
}
